﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <windows.h>
#include <QSettings>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void on_startButton_clicked();
    void on_stopButton_clicked();
    void on_restartButton_clicked();
    void on_autostartCheckBox_toggled(bool checked);
    void on_selectNginxPathButton_clicked();
    void on_installServiceButton_clicked();
    void on_uninstallServiceButton_clicked();
    void on_serviceNameLineEdit_textChanged(const QString &text);
    void checkServiceStatus();
    void on_serviceDescriptionLineEdit_textChanged(const QString &text);

private:
    Ui::MainWindow *ui;
    SERVICE_STATUS_PROCESS m_serviceStatus;
    SC_HANDLE m_scmHandle;
    SC_HANDLE m_serviceHandle;
    QString m_nginxPath;
    QString m_serviceName;
    QString m_serviceDescription;
    bool m_isServiceInstalled;
    QTimer *m_statusCheckTimer;

    void loadConfig();
    void saveConfig();
    bool installService(const QString &servicePath, const QString &serviceName, const QString &description);
    bool uninstallService();
    void updateServiceControls();
    void queryServiceStatus();
};

#endif // MAINWINDOW_H
